<template>
    <div class="purchase">
        <div class="purchase-content">
            <div class="record">
                <div class="record-title">购买记录</div>
                <div class="record-content" v-loading="loading">
                    <el-tabs v-model="activeName" class="ss">
                        <el-tab-pane label="申请订单" name="first">
                            <el-table :data="tableData1" style="width: 100%">
                                <el-table-column prop="projectName" label="项目名称" min-width="100"></el-table-column>
                                <el-table-column prop="winningNumber" label="申购签号数" min-width="100"></el-table-column>
                                <el-table-column prop label="申购签号" min-width="100">
                                    <template slot-scope="scope">
                                        <p
                                            v-for="(v,i) in scope.row.listUserPurchaseNumber"
                                            :key="i"
                                        >{{v}}</p>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="unitPrice" label="申购价格" min-width="120"></el-table-column>
                                <el-table-column
                                    prop="purchaseQuantity"
                                    label="申购数量"
                                    min-width="100"
                                ></el-table-column>
                                <el-table-column
                                    prop="purchaseTotalAmount"
                                    label="申购总额"
                                    min-width="120"
                                ></el-table-column>
                                <el-table-column prop="createTime" label="申购时间" min-width="180"></el-table-column>
                            </el-table>
                        </el-tab-pane>
                        <el-tab-pane label="中签订单" name="second">
                            <el-table :data="tableData2" style="width: 100%">
                                <el-table-column prop="projectName" label="项目名称" min-width="100"></el-table-column>
                                <el-table-column prop="winningNumber" label="申购签号数" min-width="100"></el-table-column>
                                <el-table-column prop label="申购签号" min-width="100">
                                    <template slot-scope="scope">
                                        <p
                                            v-for="(v,i) in scope.row.listUserPurchaseNumber"
                                            :key="i"
                                        >{{v}}</p>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="unitPrice" label="申购价格" min-width="120"></el-table-column>
                                <el-table-column
                                    prop="purchaseQuantity"
                                    label="申购数量"
                                    min-width="100"
                                ></el-table-column>
                                <el-table-column
                                    prop="purchaseTotalAmount"
                                    label="申购总额"
                                    min-width="120"
                                ></el-table-column>
                                <el-table-column prop="createTime" label="申购时间" min-width="180"></el-table-column>
                                <el-table-column prop label="操作" min-width="180">
                                    <template slot-scope="scope">
                                        <el-button
                                            v-if="scope.row.payIs==0?true:false"
                                            size="mini"
                                            @click.native="toPay(scope.row)"
                                            type="primary"
                                        >未付款</el-button>
                                        <span v-if="scope.row.payIs==1?true:false">
                                            <span v-if="new Date(scope.row.paymentDeadline).getTime()-new Date(scope.row.createTime).getTime()>=0">--</span>
                                            <el-button v-else size="mini" type="info" plain>未付款</el-button>
                                        </span>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </el-tab-pane>
                    </el-tabs>
                </div>
            </div>
        </div>
        <!-- 输入资金密码 -->
        <div class="bg" v-if="subscribeShowOne==2?true:false">
            <div class="subscribe" v-if="subscribeShowOne==2?true:false">
                <div class="title">
                    <span></span>
                    <span>输入资金密码</span>
                    <span @click="colseSubscribe">
                        <img src="../../assets/images/daxin/close.png" alt />
                    </span>
                </div>
                <input
                    class="password"
                    maxlength="6"
                    v-model="dealPassword"
                    type="password"
                    name
                    id
                />
                <el-button @click="verifyTwo" class="btn" type="primary">确认</el-button>
            </div>
        </div>
    </div>
</template>
<script>
// import {
//     orderTotal,
//     signOrderTotal,
//     payment,
//     checkTradePassword
// } from "../../api/api";
import qs from "qs";
export default {
    data() {
        return {
            activeName: "first",
            orLogin: window.sessionStorage.getItem("token"),
            tableData1: [],
            tableData2: [],
            loading: false,
            subscribeShowOne: 1,
            dealPassword: "",
            id: ""
        };
    },
    created() {
        console.log();
        
        this.getPurchase();
        this.getOrder();
    },
    methods: {
        colseSubscribe() {
            this.dealPassword = "";
            this.subscribeShowOne = 1;
        },
        toPay(val) {
            this.subscribeShowOne = 2;
            this.id = val.makeNewSettingId;
        },
        verifyTwo() {
            if (!this.dealPassword.match(/^\d{6}$/)) {
                this.$message({
                    message: "交易密码不能小于六位数！"
                });
                return false;
            }
            var params = {
                token: JSON.parse(this.orLogin),
                tradePassword: this.dealPassword
            };
            checkTradePassword(qs.stringify(params)).then(res => {
                if (res.data.code == 200) {
                    var datas = {
                        token: JSON.parse(this.orLogin),
                        makeNewSettingId: this.id
                    };
                    payment(qs.stringify(datas)).then(res => {
                        if (res.data.code == 200) {
                            this.getPurchase();
                            this.getOrder();
                            this.$message({
                                message: "付款成功！"
                            });
                        } else {
                            this.$message({
                                message: res.data.msg
                            });
                        }
                        this.subscribeShowOne = 1;
                    });
                } else {
                    this.$message({
                        message: res.data.msg
                    });
                }
            });
        },
        getPurchase() {
            this.loading = true;
            var params = {
                token: JSON.parse(this.orLogin)
            };
            orderTotal(params).then(res => {
                console.log(res.data);
                if (res.data.code == 200) {
                    this.loading = false;
                    this.tableData1 = res.data.data;
                }
            });
        },
        getOrder() {
            this.loading = true;
            var params = {
                token: JSON.parse(this.orLogin)
            };
            signOrderTotal(params).then(res => {
                console.log(res.data);
                if (res.data.code == 200) {
                    this.loading = false;
                    this.tableData2 = res.data.data;
                }
            });
        }
    }
};
</script>
<style lang="less" scoped>
.purchase {
    background: #fff;
    .purchase-content {
        padding: 20px 0 40px;
        margin: 0 auto;
        width: 1200px;
        .record {
            box-shadow: 0 0 2px 1px #efefef;
            .record-title {
                padding: 15px;
                box-sizing: border-box;
                font-size: 14px;
                font-weight: bold;
                color: #2d2f56;
            }
            .record-content {
                padding: 0 20px 20px;
                box-sizing: border-box;
            }
        }
    }
}
.subscribe {
    width: 500px;
    margin: 200px auto 0;
    background-color: #fff;
    padding: 20px 40px;
    box-sizing: border-box;
    border-radius: 10px;
    font-size: 14px;
    .title {
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-weight: bold;
    }
    .price {
        display: flex;
        justify-content: flex-start;
        align-items: center;
        padding: 20px;
        box-sizing: border-box;
        background-color: #ebeeff;
        border-radius: 10px;
        margin: 30px 0;
    }
    .add {
        display: flex;
        justify-content: space-between;
        > div {
            p {
                margin-bottom: 10px;
                color: #bac5cb;
            }
        }
        .add-left {
            width: 60%;
        }
        .add-right {
            width: 30%;
            > div {
                width: 100%;
                height: 38px;
                border-radius: 4px;
                outline: none;
                border: 1px solid #e6e6e6;
                text-align: center;
            }
        }
    }
    .detail {
        color: #bac5cb;
        margin: 30px 0;
        li {
            margin-bottom: 15px;
        }
        li:nth-child(2) {
            font-weight: bold;
            color: #2d2f56;
        }
    }
    .explain {
        padding: 30px 0;
        border-top: 1px solid #eee;
        li {
            color: #8c979d;
            margin-bottom: 15px;
        }
        li:first-child {
            margin-bottom: 20px;
        }
    }
    .btn {
        width: 100%;
        background-color: #6881ff;
        height: 50px;
    }
    .password {
        width: 100%;
        height: 35px;
        margin: 40px 0;
        border: 1px solid #e6e6e6;
        border-radius: 4px;
        padding: 0 15px;
        box-sizing: border-box;
        letter-spacing: 5px;
        font-weight: bold;
    }
    .yzCode {
        > p {
            margin: 30px 0;
            color: #6881ff;
            font-size: 12px;
        }
    }
    .order {
        li {
            margin-bottom: 30px;
            font-size: 12px;
            color: #bac5cb;
            > span:last-child {
                color: #2d2f56;
            }
        }
        li:first-child {
            color: #2d2f56;
            font-weight: bold;
        }
        li:nth-child(3) {
            display: flex;
            justify-content: flex-start;
            flex-wrap: wrap;
            font-size: 10px;
            span {
                display: inline-block;
                padding: 6px 10px;
                color: #ffa043;
                background-color: #fff4cc;
                border-radius: 20px;
                margin: 0 20px 10px 0;
            }
        }
    }
}
//弹框
.bg {
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 100;
    .subscribe {
        width: 500px;
        margin: 200px auto 0;
        background-color: #fff;
        padding: 20px 40px;
        box-sizing: border-box;
        border-radius: 10px;
        font-size: 14px;
        .title {
            display: flex;
            justify-content: space-between;
            align-items: center;
            font-weight: bold;
        }
        .price {
            display: flex;
            justify-content: flex-start;
            align-items: center;
            padding: 20px;
            box-sizing: border-box;
            background-color: #ebeeff;
            border-radius: 10px;
            margin: 30px 0;
        }
        .add {
            display: flex;
            justify-content: space-between;
            > div {
                p {
                    margin-bottom: 10px;
                    color: #bac5cb;
                }
            }
            .add-left {
                width: 60%;
            }
            .add-right {
                width: 30%;
                > div {
                    width: 100%;
                    height: 38px;
                    border-radius: 4px;
                    outline: none;
                    border: 1px solid #e6e6e6;
                    text-align: center;
                }
            }
        }
        .detail {
            color: #bac5cb;
            margin: 30px 0;
            li {
                margin-bottom: 15px;
            }
            li:nth-child(2) {
                font-weight: bold;
                color: #2d2f56;
            }
        }
        .explain {
            padding: 30px 0;
            border-top: 1px solid #eee;
            li {
                color: #8c979d;
                margin-bottom: 15px;
            }
            li:first-child {
                margin-bottom: 20px;
            }
        }
        .btn {
            width: 100%;
            background-color: #6881ff;
            height: 50px;
        }
        .password {
            width: 100%;
            height: 35px;
            margin: 40px 0;
            border: 1px solid #e6e6e6;
            border-radius: 4px;
            padding: 0 15px;
            box-sizing: border-box;
            letter-spacing: 5px;
            font-weight: bold;
        }
        .yzCode {
            > p {
                margin: 30px 0;
                color: #6881ff;
                font-size: 12px;
            }
        }
        .order {
            li {
                margin-bottom: 30px;
                font-size: 12px;
                color: #bac5cb;
                > span:last-child {
                    color: #2d2f56;
                }
            }
            li:first-child {
                color: #2d2f56;
                font-weight: bold;
            }
            li:nth-child(3) {
                display: flex;
                justify-content: flex-start;
                flex-wrap: wrap;
                font-size: 10px;
                span {
                    display: inline-block;
                    padding: 6px 10px;
                    color: #ffa043;
                    background-color: #fff4cc;
                    border-radius: 20px;
                    margin: 0 20px 10px 0;
                }
            }
        }
    }
}
</style>